package mapping

import (
	"pay/model"
	"pay/model/entity"
	"pay/utils"
)

// FeePlansEntityToDto entity data transfer
func FeePlansEntityToDto(feePlans []*entity.FeePlan) []*model.FeePlanInfo {
	out := make([]*model.FeePlanInfo, 0, len(feePlans))
	for _, c := range feePlans {
		out = append(out, FeePlanEntityToDto(c))
	}
	return out
}

// FeePlanEntityToDto entity data transfer
func FeePlanEntityToDto(e *entity.FeePlan) *model.FeePlanInfo {

	var (
		packs = model.NewPlanPacks(e.Packs, &model.PlanPackOption{
			PlanId: utils.GetValuePointer(e.Id),
			Type:   utils.GetValuePointer(model.FeePlanType(e.Type)),
		})
		//fGetYearlyMoney = func() int32 {
		//
		//	if model.FeePlanType(e.Type) == model.FeePlanTypeYearlyRenewalPlan {
		//		return int32(packs[0].Money)
		//	}
		//
		//	return 0
		//}()
	)
	return &model.FeePlanInfo{
		Id:          e.Id,
		Name:        e.Name,
		FeeTypeName: model.FeePlanType(e.Type).String(),
		Content:     packs.String(),
		Type:        e.Type,
		Enable:      e.Enable,
		//YearlyMoney: fGetYearlyMoney,
		Packs:     e.Packs,
		CreatedAt: e.CreatedAt,
		UpdatedAt: e.UpdatedAt,
	}
}
